package random.generators;

import java.util.ArrayList;
import java.util.List;

public class RayleighDistributionGenerator implements DistributionGenerator{

	private double variance;
	
	public RayleighDistributionGenerator(double variance){
		this.variance = variance;
	}
	
	@Override
	public List<Double> generateRandomNumbers(int n) {
		List<Double> ret = new ArrayList<Double>(n);
		for( int i = 0; i < n; i++){
			double x = Math.random(); // uniforme en 0 -1 
			double y = variance * Math.sqrt(-2 * Math.log(1 - x));
			ret.add(y);
		}
		return ret;
	}

	@Override
	public Double distributionFunction(double x) {
		return 1 - Math.exp(-1*(Math.pow(x, 2)/2*Math.pow(variance, 2)));
	}

}
